/**
 * Project Name:filmbAdmin1 File Name:BaseProxy.java Package
 * Name:com.filmb.admin.base.proxy Date:2014年10月28日上午10:10:49 Copyright (c) 2014
 * 
 */
/**
 * @projectName:filmbAdmin1
 * @packageName:com.filmb.admin.base.proxy
 * @className:BaseProxy.java
 * 
 * @createTime:2014年10月28日-上午10:10:49
 * 
 * 
 */

package com.yn.xr.common.proxy;

import java.util.Map;

import net.sf.ezmorph.object.DateMorpher;
import net.sf.json.JSONObject;

import com.yn.xr.common.util.HttpClientUtils;
import com.yn.xr.common.util.StringUtils;


/**
 * @description: 父代理类
 * @fileName:BaseProxy.java
 * @createTime:2014年10月28日 上午10:10:49
 * @author:肖震
 * @version 1.0.0
 * 
 */
public class BaseProxy<T>
{
	
	
	public String middlewareServerUrl;
	//新闻资讯接口URL
	public String newsapiInterfaceUrl;
	/**
	 * 
	 * @function:http get请求
	 * @param url 请求地址
	 * @return String 返回结果
	 * @exception
	 * @author:肖震
	 * @since 1.0.0
	 */
	public String httpGet(String url)
	{
		String result = HttpClientUtils.httpGet(StringUtils.trimAllEmpty(url));
		return result;
	}
	/**
	 * 
	 * @function: Get请求返回Jsonobject对象 
	 * @param url
	 * @return String   
	 * @exception 
	 * @author:肖震   
	 * @since  1.0.0
	 */
	public JSONObject httpGetJsonObject(String url)
	{
		String jsonStr=httpGet(url);
		JSONObject jsonobject = strToJsonObject(jsonStr);
        return jsonobject;
        
	}
	/**   
	 * @function:  
	 * @param jsonStr
	 * @return JSONObject   
	 * @exception 
	 * @author:肖震   
	 * @since  1.0.0   
	*/
	public JSONObject strToJsonObject(String jsonStr)
	{
		if(jsonStr!=null&&jsonStr.contains("@xsi.type"))
		{
			jsonStr=jsonStr.replace("@xsi.type", "xsiType");
		}
		net.sf.json.util.JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(new String[] {"yyyy-MM-dd HH:mm:ss"}), true);
		
        JSONObject jsonobject = JSONObject.fromObject(jsonStr);
		return jsonobject;
	}
	/**
	 * 
	 * @function:https get请求
	 * @param url 请求地址
	 * @return String 返回结果
	 * @exception
	 * @author:肖震
	 * @since 1.0.0
	 */
	public String httpsGet(String url)
	{
		String result = HttpClientUtils.httpsGet(StringUtils.trimAllEmpty(url));
		return result;
	}
	
	/**
	 * 
	 * @function: http post请求
	 * @param reqURL 请求地址
	 * @param params 请求参数
	 * @return String 返回结果
	 * @exception
	 * @author:肖震
	 * @since 1.0.0
	 */
	public String httpPost(String url, Map<String, String> params)
	{
		String result = HttpClientUtils.httpPost(StringUtils.trimAllEmpty(url), params);
		return result;
	}
	/**
	 * 
	 * @function: http post提交返回json对象 
	 * @param url
	 * @param params
	 * @return JSONObject   
	 * @exception 
	 * @author:肖震   
	 * @since  1.0.0
	 */
	public JSONObject httpPostJsonObject(String url, Map<String, String> params)
	{
		String result = httpPost(url, params);
		JSONObject jsonobject = strToJsonObject(result);
        return jsonobject;		
	}
	
	/**
	 * 
	 * @function:https post请求
	 * @param reqURL请求地址
	 * @param params请求参数
	 * @return String 返回结果
	 * @throws Exception 
	 * @exception
	 * @author:肖震
	 * @since 1.0.0
	 */
	public String httpsPost(String url, Map<String, String> params) throws Exception
	{
		String result = HttpClientUtils.httpsPost(StringUtils.trimAllEmpty(url), params);
		return result;
	}
	
	
	
	public String getMiddlewareServerUrl()
	{
		return middlewareServerUrl;
	}

	
	public void setMiddlewareServerUrl(String middlewareServerUrl)
	{
		this.middlewareServerUrl = middlewareServerUrl;
	}
	
	public String getNewsapiInterfaceUrl()
	{
		return newsapiInterfaceUrl;
	}
	
	public void setNewsapiInterfaceUrl(String newsapiInterfaceUrl)
	{
		this.newsapiInterfaceUrl = newsapiInterfaceUrl;
	}
	
	
}
